package iscript.gameFramework.GameLite.directEvent
{
	import iscript.gameFramework.GameLite.Game;
	import iscript.gameFramework.GameLite.thread.task.TaskAction;
	
	/**
	 * 发送消息处理逻辑
	 */
	internal class DirectEventSendAction extends TaskAction
	{
		
		private var _listenerData:DirectEventListenerPool;
		public var eventName:String;
		public var eventData:DirectEventParameter;
		
		public function DirectEventSendAction(listenerData:DirectEventListenerPool)
		{
			_listenerData = listenerData;
		}
		
		override public function execute():void
		{
			super.execute();
			var len:int = _listenerData.registerEventName.length;
			var type:String;
			for (var i:int = 0; i < len; i++)
			{
				if (_listenerData.registerEventName[i] == eventName)
				{
					if (_listenerData.registerEventAction[i] is Function)
					{
						type = "Function";
						_listenerData.registerEventAction[i](eventData);
					}
					if (_listenerData.registerEventAction[i] is DirectEventAction)
					{
						type = "DirectEventAction";
						DirectEventAction(_listenerData.registerEventAction[i]).eventParameter = eventData;
						DirectEventAction(_listenerData.registerEventAction[i]).execute();
					}
					if (Game.IsDebugMode)
						trace("[DirectEvent recevie: " + type + " " + eventName + "]")
				}
			}
			
			this.finish();
		
		}
	}

}